using System;
using System.IO;
using Microsoft.DirectX.Direct3D;

namespace SharpWind.Resources.Creators
{
	public class ShaderFromFileCreator : IResourceCreator<Shader>
	{
		private string path = string.Empty;

		public ShaderFromFileCreator( string path )
		{
			if( path != null && path != string.Empty && File.Exists( path ) )
			{
				this.path = path;
			} // if (path)
			else
			{
				throw new Exception();
			} // else
		}

		public Shader Create()
		{
			Shader shader = new Shader();
			string errors;
			shader.D3DEffect = Effect.FromFile( Engine.Instance.Renderer.Device, this.path, null, null, ShaderFlags.None, null, out errors );

			return shader;
		}
	}
}
